package com.doit.demo.day02.sources;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Arrays;

/**
 * @DATE 2022/2/15/16:24
 * @Author MDK
 * @Version 2021.2.2
 * fromElements、fromCollection是一个 [非并行的] Source
 * 基于集合的Source都是有限的数据流  数据处理完成后程序会退出
 **/
public class CollectionSource {
    public static void main(String[] args) throws Exception {
        Configuration configuration = new Configuration();
        configuration.setInteger("rest.port",8081);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(configuration);

        //DataStreamSource<Integer> nums = env.fromCollection(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9));
        DataStreamSource<Integer> nums = env.fromElements(1, 2, 3, 4, 5, 6, 7, 8, 9);
        System.out.println("fromElements创建的DataStream并行度:"+nums.getParallelism());
        nums.print();

        env.execute();
    }
}
